﻿Imports MySql.Data.MySqlClient
Public Class SqlLogin
    Dim connStr As String
    Function mysql_connect()
        Try
            Dim connection As New MySqlConnection(connStr)
            connection.Open()
            connection.Close()
            Return 1
        Catch ex As Exception
            Return 0
        End Try
    End Function
    Private Sub MainWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Sql_Username.Text = My.Settings.Username
        Sql_Password.Text = My.Settings.Password
        Sql_Host.Text = My.Settings.SqlHost
        Sql_Db.Text = My.Settings.World_DB
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If CheckBox1.Checked Then
            My.Settings.Username = Sql_Username.Text
            My.Settings.Password = Sql_Password.Text
            My.Settings.SqlHost = Sql_Host.Text
            My.Settings.World_DB = Sql_Db.Text
            My.Settings.Save()
        End If
        connStr = "Database=" & Sql_Db.Text & ";" & _
        "Data Source=" & Sql_Host.Text & ";" & _
        "User Id=" & Sql_Username.Text & ";Password=" & Sql_Password.Text & ""
        If mysql_connect() = 1 Then
            MsgBox("Connection Successful!")
            connInfo = connStr
            Me.Hide()
            DbEditor.Show()
        Else
            MsgBox("Error connecting to MySQL Database!")
        End If
    End Sub
End Class
